package haida.pym_system.site.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import haida.pym_system.site.pojo.Site;
import haida.pym_system.site.mapper.SiteMapper;
import haida.pym_system.site.pojo.User;
import haida.pym_system.site.pojo.Vo;
import haida.pym_system.site.service.ISiteService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 大龙
 * @since 2020-09-28
 */
@Service
public class SiteServiceImpl extends ServiceImpl<SiteMapper, Site> implements ISiteService {
    @Resource
    private SiteMapper siteMapper;

    @Override
    public void addSite(Site site) {
        siteMapper.addSite(site);
    }

    @Override
    public void deleteSite(int siteID) {
        siteMapper.deleteSite(siteID);
    }

    @Override
    public void updateSite(Site site) {
        siteMapper.updateSite(site);
    }

    @Override
    public Vo<Site> findAllSite(String content, int current, int size) {

        if (content == null&&content.equals("")) {
            current = 1;
        }
        System.out.println(content+current+size);

        Page<Site> page = new Page<>(current, size);//参数一是当前页，参数二是每页个数
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.like("username", content);
        List<Site> allSite = siteMapper.findAllSite(page);
        Vo<Site> siteVo = new Vo<>();
        siteVo.setContent(content);
        siteVo.setCurrent(current);
        siteVo.setSize(size);
        siteVo.setTotal(page.getTotal());
        siteVo.setList(allSite);
        return siteVo;

    }

    @Override
    public Site findASite(int siteID) {
        return siteMapper.findASite(siteID);
    }

    @Override
    public List<Site> findAllAbleSite() {
        return siteMapper.findAllAbleSite();
    }

    public List<Site> selectUserListPage(Page<Site> page) {
        return this.baseMapper.selectUserListPage(page);
    }
}
